<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>tinymce学习</title>
  <script language="javascript" type="text/javascript" src="tinymce/js/tinymce/tinymce.min.js"></script>

</head>

<body>
<textarea id="textarea" >
    Welcome to TinyMCE!

  </textarea>
<script>
    tinymce.init({
        //设置为中文
        language:'zh_CN',
        //将TinyMCE插件放入‘textarea’ID为textarea的标签里
        selector: 'textarea#textarea',
        //配置插件
        plugins: [
            'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
            'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
            'save table contextmenu directionality emoticons template paste imagetools textcolor'
        ],
        //工具框
        toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | ' +
            'bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons',
        image_advtab: true,
        table_default_styles: {
            width: '100%',
            borderCollapse: 'collapse'
        },
        // 是否开启图片标题设置的选择，这里设置否
        image_title: false,
        automatic_uploads: true,
        // 图片异步上传处理函数
        images_upload_handler: (blobInfo, success, failure) => {
            //创建xhr对象
            var xhr = new XMLHttpRequest();
            xhr.withCredentials = false;
            //第一个参数是请求方式，第二个参数是请求地址
            xhr.open('POST', 'http://localhost:63342/hexu_event02/web/tinymce_01.html?_ijt=84ck1dsi9um4eip6rf716jnerd');
            //注册相关事件回调处理函数
            xhr.onload = function () {
                //如果服务器没有正常处理了请求并响应就报错
                if (xhr.status !== 200) {
                    failure('HTTP Error: ' + xhr.status);
                    return;
                }
                //返回结果,将字符串转成json对象
                var json = JSON.parse(xhr.responseText);
                if (!json || typeof json.location !== 'string') {
                    failure('Invalid JSON: ' + xhr.responseText);
                    return;
                }
                success(json.location);
            };
            //构造表单数据
            var formData = new FormData();
            formData.append('files', blobInfo.blob(), blobInfo.filename());
            //发送数据
            xhr.send(formData);
        }

    })

</script>
</body>
</html>